<template>
  <div class="my">
    <div class="top">
      <div class="top1">
        <div class="left">
          <img
            @click="
              $router.push(
                `/home/myInfo?id=${userInfo.id}&&intro=${userInfo.intro}`
              )
            "
            v-if="userInfo.photo"
            :src="userInfo.photo"
            mode=""
          />
          <img
            @click="$router.push('/home/myInfo?id=' + userInfo.id)"
            v-else
            src="@/assets/logo.png"
            mode=""
          />
          <div class="txt">
            <div class="name">{{ userInfo.name }}</div>
            <div class="identity">申请认证</div>
          </div>
        </div>
        <div class="right">
          <i class="iconfont">&#xe63f;</i>
          <div class="txt">今日阅读5分钟</div>
        </div>
      </div>
      <div class="top2">
        <div class="top2-item">
          <div class="num">0</div>
          <div class="txt">动态</div>
        </div>
        <div class="top2-item">
          <div class="num">{{ userInfo.follow_count }}</div>
          <div class="txt">关注</div>
        </div>
        <div class="top2-item">
          <div class="num">{{ userInfo.fans_count }}</div>
          <div class="txt">粉丝</div>
        </div>
      </div>
      <div class="top3">
        <div class="top3-item">
          <i class="iconfont">&#xe63c;</i>
          <div class="txt">收藏</div>
        </div>
        <div class="top3-item">
          <i class="iconfont">&#xe603;</i>
          <div class="txt">历史</div>
        </div>
        <div class="top3-item">
          <i class="iconfont">&#xe606;</i>
          <div class="txt">作品</div>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="content1">
        <van-cell title="消息通知" is-link>
          <template #icon>
            <i class="iconfont">&#xe656;</i>
          </template>
        </van-cell>
        <van-cell title="实名认证" is-link>
          <template #icon>
            <i class="iconfont">&#xe64d;</i>
          </template>
        </van-cell>
      </div>
      <div class="content2">
        <van-cell title="用户反馈" is-link>
          <template #icon>
            <i class="iconfont">&#xe63f;</i>
          </template>
        </van-cell>
        <van-cell title="在线咨询" is-link>
          <template #icon>
            <i class="iconfont">&#xe65b;</i>
          </template>
        </van-cell>
        <van-cell title="系统设置" is-link>
          <template #icon>
            <i class="iconfont">&#xe646;</i>
          </template>
        </van-cell>
      </div>
      <van-button @click="exit" class="exit" type="primary" block
        >退出</van-button
      >
    </div>
  </div>
</template>

<script>
import { removeLocalToken } from '@/utils/token'
import { getUserInfo } from '@/api/my'
export default {
  data () {
    return {
      userInfo: '' // 用户信息
    }
  },
  methods: {
    // 退出
    exit () {
      // 0.提示退出登录
      this.$toast.loading({
        message: '退出登录成功'
      })
      // 1.删除token
      removeLocalToken('token')
      // 2.跳转到登录页
      this.$router.push('/')
    },
    // 获取用户信息
    async getUserInfo () {
      const res = await getUserInfo()
      this.userInfo = res.data
    }
  },
  created () {
    // 获取用户信息
    this.getUserInfo()
  }
}
</script>

<style lang="less" scoped>
.my {
  .top {
    position: relative;
    background: @color;
    padding: 0 0 80px @p15;
    .top1 {
      padding: 30px 0;
      display: flex;
      justify-content: center;
      align-items: center;
      .left {
        display: flex;
        justify-content: center;
        align-items: center;
        flex: 1;
        img {
          width: 70px;
          height: 70px;
          border-radius: 50%;
        }
        .txt {
          flex: 1;
          font-size: 14px;
          margin-left: 10px;
          .name {
            color: #fff;
            padding-bottom: 8px;
          }
          .identity {
            width: 70px;
            padding: 2px;
            background: #fff;
            color: @color;
            border-radius: 10px;
            text-align: center;
          }
        }
      }
      .right {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 12px;
        border-radius: 17px 0 0 17px;
        background: rgba(0, 0, 0, 0.1);
        color: #fff;
        i {
          padding: 7px;
        }
        .txt {
          width: 60px;
          padding: 4px 0;
        }
      }
    }
    .top2 {
      display: flex;
      justify-content: space-between;
      padding: 0 45px 0 30px;
      color: #fff;
      font-size: 16px;
      .top2-item {
        text-align: center;
      }
    }
    .top3 {
      position: absolute;
      display: flex;
      bottom: -20px;
      padding: 7px 30px;
      font-size: 16px;
      background: #fff;
      border-radius: 10px;
      .top3-item {
        text-align: center;
        i {
          font-size: 28px;
        }
      }
      .top3-item:first-child i {
        color: #f08081;
      }
      .top3-item:nth-child(2n) i {
        color: #ffcb85;
      }
      .top3-item:nth-child(3n) i {
        color: #91aaff;
      }
      .top3-item:nth-child(2n) {
        margin: 0 95px;
      }
    }
  }
  .content {
    background-color: #f5f7f9;
    padding: 30px @p15;
    .van-cell {
      height: 50px;
      i {
        font-size: 16ppx;
        font-weight: 500;
      }
      .iconfont {
        color: @color;
        font-size: 22px;
        margin-right: 5px;
        font-weight: 400;
      }
    }
    .exit {
      background: @color;
      border: 0;
      margin-top: 10px;
      text-decoration: none;
      border-radius: 10px;
    }
    .content1 {
      margin-bottom: 10px;
    }
  }
}
</style>
